﻿using Eneta.Portal.Forum.Core.Domain.Entities;
using Microsoft.SharePoint;

namespace Eneta.Portal.Forum.Core.Service.Builders
{
    public class ForumAccessListBuilder : ListBuilder
    {
        // Methods
        public ForumAccessListBuilder()
        {
            base.listName = "spsforums_forum_access";
        }

        public override void AddFields()
        {
            base.AddFieldToList("ForumID", (SPFieldType)9, false);
            base.AddFieldToList("GroupID", (SPFieldType)9, false);
        }

        public override void AddSampleData()
        {
            if (base.ListExists)
            {
                Permission permission = new Permission();
                string[] values = new string[6];
                permission.SetPermission(Permission.Rights.Read, true);
                values[0] = "Title";
                values[1] = permission.ToString();
                values[2] = "ForumID";
                values[3] = "1";
                values[4] = "GroupID";
                values[5] = "1";
                base.AddListValues(values);
                permission.SetPermission(Permission.Rights.Read, true);
                values[0] = "Title";
                values[1] = permission.ToString();
                values[2] = "ForumID";
                values[3] = "0";
                values[4] = "GroupID";
                values[5] = "1";
                base.AddListValues(values);
                permission.SetPermission(Permission.Rights.Add, true);
                permission.SetPermission(Permission.Rights.Edit, true);
                permission.SetPermission(Permission.Rights.Reply, true);
                permission.SetPermission(Permission.Rights.Delete, true);
                values[0] = "Title";
                values[1] = permission.ToString();
                values[2] = "ForumID";
                values[3] = "1";
                values[4] = "GroupID";
                values[5] = "2";
                base.AddListValues(values);
                permission.SetPermission(Permission.Rights.Add, true);
                permission.SetPermission(Permission.Rights.Edit, true);
                permission.SetPermission(Permission.Rights.Reply, true);
                permission.SetPermission(Permission.Rights.Delete, true);
                values[0] = "Title";
                values[1] = permission.ToString();
                values[2] = "ForumID";
                values[3] = "0";
                values[4] = "GroupID";
                values[5] = "2";
                base.AddListValues(values);
                permission.SetPermission(Permission.Rights.Admin, true);
                values[0] = "Title";
                values[1] = permission.ToString();
                values[2] = "ForumID";
                values[3] = "1";
                values[4] = "GroupID";
                values[5] = "3";
                base.AddListValues(values);
                permission.SetPermission(Permission.Rights.Admin, true);
                values[0] = "Title";
                values[1] = permission.ToString();
                values[2] = "ForumID";
                values[3] = "0";
                values[4] = "GroupID";
                values[5] = "3";
                base.AddListValues(values);
            }
        }
    }
}
